package com.ruoyi.business.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.ruoyi.business.domain.OrderManage;
import com.ruoyi.business.domain.OrderNum;
import com.ruoyi.business.domain.RankOrder;
import com.ruoyi.business.domain.dto.OrderManageDTO;
import com.ruoyi.business.mapper.OrderManageMapper;
import com.ruoyi.business.service.IOrderManageService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.DictConstants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.CancelReason;
import com.ruoyi.common.enums.OrderStatus;
import com.ruoyi.common.enums.RoleKey;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.*;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.wechat.service.IAsyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 工单管理Service业务层处理
 *
 * @author D_xiao
 * @date 2022-08-14
 */
@Service
public class OrderManageServiceImpl implements IOrderManageService {

    private static final Logger log = LoggerFactory.getLogger(OrderManageServiceImpl.class);

    @Autowired
    private OrderManageMapper orderManageMapper;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    private IAsyncService asyncService;

    /**
     * 查询工单管理
     *
     * @param id 工单管理主键
     * @return 工单管理
     */
    @Override
    public OrderManage selectOrderManageById(Long id) {
        OrderManage orderManage = orderManageMapper.selectOrderManageById(id);
        // 工单类型赋值
        orderManage.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, orderManage.getOrderType()));
        // 工单状态赋值
        orderManage.setOrderStatusShow(DictUtils.getDictLabel(DictConstants.ORDER_STATUS, orderManage.getOrderStatus()));
        return orderManage;
    }

    /**
     * 查询工单管理列表
     *
     * @param orderManage 工单管理
     * @return 工单管理
     */
    @Override
    public List<OrderManage> selectOrderManageList(OrderManage orderManage) {
        List<OrderManage> orderList = orderManageMapper.selectOrderManageList(orderManage);
        for(OrderManage oneOrder : orderList){
            oneOrder.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, oneOrder.getOrderType()));
        }
        return orderList;
    }

    /**
     * 查询工单管理列表(按用户权限过滤)
     *
     * @param orderManage 工单管理
     * @return 工单管理
     */
    @Override
    public List<OrderManageDTO> selectOrderManageListByUserAuth(OrderManage orderManage) {
        List<OrderManageDTO> orderList = orderManageMapper.selectOrderManageListByUserAuth(orderManage);
        for(OrderManageDTO oneOrder : orderList){
            oneOrder.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, oneOrder.getOrderType()));
        }
        return orderList;
    }

    /**
     * 查询工单管理列表(按运维权限过滤)
     *
     * @param orderManage 工单管理
     * @return 工单管理
     */
    @Override
    public List<OrderManageDTO> selectOrderManageListByOptAuth(OrderManage orderManage) {
        // 待抢单
        List<OrderManageDTO> optOrderList = new ArrayList<>();
        if(StringUtils.isEmpty(orderManage.getOrderStatus())){
            optOrderList = orderManageMapper.selectOrderManageListByOptAuth(orderManage);
        }else if(StringUtils.isNotEmpty(orderManage.getOrderStatus()) && OrderStatus.GRAB.getCode().equals(orderManage.getOrderStatus())){
            optOrderList = orderManageMapper.selectOrderManageListByAdminAuth(orderManage);
        }else{
            optOrderList = orderManageMapper.selectOrderManageListByOptAuth(orderManage);
        }
        for(OrderManageDTO oneOrder : optOrderList){
            oneOrder.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, oneOrder.getOrderType()));
        }
        return optOrderList;
    }


    /**
     * 响应请求分页数据
     */
    protected TableDataInfo getDataTable(ListPageUtil<?> list) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list.getPagedList());
        rspData.setTotal(list.getTotal());
        return rspData;
    }

    /**
     * 查询工单管理列表(按管理员权限过滤)
     *
     * @param orderManage 工单管理
     * @return 工单管理
     */
    @Override
    public List<OrderManageDTO> selectOrderManageListByAdminAuth(OrderManage orderManage) {
        List<OrderManageDTO> orderList = orderManageMapper.selectOrderManageListByAdminAuth(orderManage);
        for(OrderManageDTO oneOrder : orderList){
            oneOrder.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, oneOrder.getOrderType()));
        }
        return orderList;
    }

    /**
     * 新增工单管理
     *
     * @param orderManage 工单管理
     * @return 结果
     */
    @Override
    public int insertOrderManage(OrderManage orderManage) {
        orderManage.setCreateTime(DateUtils.getNowDate());
        String code = generateOrderCode();
        orderManage.setOrderCode(code);
        // 默认非派单
        orderManage.setIsSend("0");
        // 默认待抢单
        orderManage.setOrderStatus(OrderStatus.GRAB.getCode());
        int i = orderManageMapper.insertOrderManage(orderManage);
        // 异步推送抢单消息
        asyncSendMsg(orderManage);
        return i;
    }

    /**
     * 功能描述:    异步推送抢单消息
     *
     * @Author wanghc
     * @Date 2022/08/22 15:59
     * @param orderManage
     * @return
     */
    private void asyncSendMsg(OrderManage orderManage){
        // 工单类型赋值
        orderManage.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, orderManage.getOrderType()));
        // 工单状态赋值
        orderManage.setOrderStatusShow(DictUtils.getDictLabel(DictConstants.ORDER_STATUS, orderManage.getOrderStatus()));
        asyncService.executeAsyncSendGrabMsg(orderManage);
    }

    /**
     * @param
     * @return
     * @description 生成单号
     * @author Jensen
     * @since 2022/8/20 19:02
     */
    private String generateOrderCode() {
        String dataStr = DateUtils.getYear();
        String orderCode = redisCache.getIncrementNum(dataStr);
        return orderCode;
    }

    /**
     * 修改工单管理
     *
     * @param orderManage 工单管理
     * @return 结果
     */
    @Override
    public int updateOrderManage(OrderManage orderManage) {
        return orderManageMapper.updateOrderManage(orderManage);
    }

    /**
     * 批量删除工单管理
     *
     * @param ids 需要删除的工单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManageByIds(Long[] ids) {
        return orderManageMapper.deleteOrderManageByIds(ids);
    }

    /**
     * 修改工单状态
     *
     * @param orderManage 工单管理
     * @return 结果
     */
    @Override
    public int updateOrderStatus(OrderManage orderManage) {
        return orderManageMapper.updateOrderStatus(orderManage);
    }

    /**
     * 删除工单管理信息
     *
     * @param id 工单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManageById(Long id) {
        return orderManageMapper.deleteOrderManageById(id);
    }

    @Override
    public AjaxResult todayOrderNum() {
        String startTime = DateUtils.getDate() + " 00:00:00";
        String endTime = DateUtils.getDate() + " 23:59:59";
        List<OrderManage> orderManages = orderManageMapper.selectOrderManageListToday(startTime, endTime);
        Map<String, Integer> map = new HashMap<>();
        map.put("stayOrder", 0);
        map.put("ordering", 0);
        map.put("ordered", 0);
        map.put("orderCancel", 0);
        int cnt = 0;
        for (OrderManage one : orderManages) {
            cnt += one.getId();
            switch (one.getOrderStatus()) {
                case "2":
                    map.put("stayOrder", Integer.parseInt(String.valueOf(one.getId())));
                    break;
                case "5":
                    map.put("ordering", Integer.parseInt(String.valueOf(one.getId())));
                    break;
                case "7":
                    map.put("ordered", Integer.parseInt(String.valueOf(one.getId())));
                    break;
                case "4":
                    map.put("orderCancel", map.get("orderCancel") + Integer.parseInt(String.valueOf(one.getId())));
                    break;
                case "6":
                    map.put("orderCancel", map.get("orderCancel") + Integer.parseInt(String.valueOf(one.getId())));
                    break;
            }

        }
        map.put("total", cnt);
        return AjaxResult.success().put("data", map);
    }

    @Override
    public AjaxResult orderUser(int num) {
        String startTime = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -num), "yyyy-MM-dd HH:mm:ss");
        String endTime = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss");
        List<OrderManage> orderManages = orderManageMapper.selectOrderManageListWeekOrMonth(startTime, endTime);
        String[] xData = new String[num];
        Integer[] yData = new Integer[num];
        Map<String, Integer> map = new HashMap<>();
        for (OrderManage one : orderManages) {
            map.put(one.getCreateBy().substring(3), Integer.parseInt(String.valueOf(one.getId())));
        }
        int j = 0;
        for (int i = num - 1; i >= 0; i--) {
            xData[j] = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -i), "MM-dd");
            yData[j] = map.get(xData[j]) == null ? 0 : map.get(xData[j]);
            j++;
        }
        AjaxResult ajaxResult = AjaxResult.success().put("xData", xData).put("yData", yData);
        return ajaxResult;
    }

    @Override
    public AjaxResult orderRank(int num) {
        String startTime = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -num), "yyyy-MM-dd HH:mm:ss");
        String endTime = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss");
        List<OrderManage> rankingWeekOrMonth = orderManageMapper.selectOrderManageRankingWeekOrMonth(startTime, endTime);
        List<RankOrder> ranks = new ArrayList<>();
        RankOrder rank;
        AtomicInteger atomicInteger = new AtomicInteger(1);
        for (OrderManage one : rankingWeekOrMonth) {
            rank = new RankOrder();
            rank.setOrder(atomicInteger.getAndAdd(1));
            rank.setUser(one.getReceiveBy());
            rank.setNum(one.getId());
            ranks.add(rank);
        }
        AjaxResult ajaxResult = AjaxResult.success().put("rank", ranks);
        return ajaxResult;
    }

    /**
     * 查询工单详情 app
     *
     * @param id 工单管理主键
     * @return 工单管理
     */
    @Override
    public OrderManage getOrderInfo(Long id) {
        OrderManage orderManage = orderManageMapper.selectOrderManageById(id);
        // 工单类型赋值
        orderManage.setOrderTypeShow(DictUtils.getDictLabel(DictConstants.ORDER_TYPE, orderManage.getOrderType()));
        // 工单状态赋值
        orderManage.setOrderStatusShow(DictUtils.getDictLabel(DictConstants.ORDER_STATUS, orderManage.getOrderStatus()));
//        Map<String,String> map = userService.getAllUserNameMap();

        // 报单人姓名赋值、手机号
        if(StringUtils.isNotEmpty(orderManage.getCreateBy())){
            SysUser createBy = userService.selectUserByUserName(orderManage.getCreateBy());
            orderManage.setCreateBy(createBy.getNickName());
            orderManage.setSubmitPhone(createBy.getPhonenumber());
        }
        // 接单人姓名赋值、手机号
        if(StringUtils.isNotEmpty(orderManage.getReceiveBy())){
            SysUser receiveBy = userService.selectUserByUserName(orderManage.getReceiveBy());
            orderManage.setReceiveByName(receiveBy.getNickName());
            orderManage.setReceivePhone(receiveBy.getPhonenumber());
        }
        // 取消人姓名赋值
        if(StringUtils.isNotEmpty(orderManage.getCancelBy())){
            SysUser cancelBy = userService.selectUserByUserName(orderManage.getCancelBy());
            orderManage.setCancelBy(cancelBy.getNickName());
        }
        // 取消原因赋值
        if(StringUtils.isNotEmpty(orderManage.getCancelReason())){
            orderManage.setCancelReasonShow(DictUtils.getDictLabel(DictConstants.CANCEL_REASON, orderManage.getCancelReason()));
        }

        return orderManage;
    }

    /**
     * 功能描述:    接单
     *
     * @Author wanghc
     * @Date 2022/08/22 16:48
     * @param orderManage 工单
     * @return int
     */
    @Override
    public int receiveOrder(OrderManage orderManage) {
        int result = 0;
        OrderManage databaseOrder = orderManageMapper.selectOrderManageById(orderManage.getId());
        // 未查询到工单
        if(null == databaseOrder){
            throw new ServiceException("未查询到当前工单,请联系管理员处理");
        }
        // 工单状态为空
        if(StringUtils.isEmpty(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单状态缺失，请联系管理员处理");
        }
        // 锁控制
        StringBuilder key = new StringBuilder(CacheConstants.LOCK_KEY).append(orderManage.getId());
        try {
            Boolean hasLock = redisCache.getLock(key.toString());
            if (hasLock) {
                log.info("get lock success: {}", key);
                if (Integer.parseInt(databaseOrder.getOrderStatus()) > 3) {
                    throw new ServiceException("该工单已被抢单");
                }
                // 接单后状态变为进行中
                orderManage.setOrderStatus(OrderStatus.ONGOING.getCode());
                result = orderManageMapper.updateReceiveOrder(orderManage);
                // 接单通知报单人
                if (OrderStatus.ONGOING.getCode().equals(orderManage.getOrderStatus())) {
                    asyncService.executeAsyncSendReceiveMsg(orderManage);
                }
            } else {
                log.info("get lock error : {}", key);
                throw new ServiceException("抢单失败，请稍后再试");
            }
        } catch (Exception e) {
            log.error("receiveOrder error:", e);
            throw new ServiceException("抢单服务异常，请联系管理员处理");
        }finally {
            redisCache.deleteObject(key.toString());
            log.info("release lock : {}", key);
        }
        return result;
    }

    /**
     * 功能描述:    取消工单
     *
     * @Author wanghc
     * @Date 2022/08/22 16:48
     * @param orderManage 工单
     * @return int
     */
    @Override
    public int cancelOrder(OrderManage orderManage) {
        OrderManage databaseOrder = orderManageMapper.selectOrderManageById(orderManage.getId());
        // 未查询到工单
        if(null == databaseOrder){
            throw new ServiceException("未查询到当前工单,请联系管理员处理");
        }
        // 工单状态为空
        if(StringUtils.isEmpty(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单状态缺失，请联系管理员处理");
        }
        // 工单已取消
        if(OrderStatus.BEFORECANCEL.getCode().equals(databaseOrder.getOrderStatus()) ||
                OrderStatus.AFTERCANCEL.getCode().equals(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单已取消，请勿重复取消");
        }
        // 工单已完成
        if(Integer.parseInt(databaseOrder.getOrderStatus()) > 6){
            // 未接单状态取消，状态变为已取消（接单前）
            orderManage.setOrderStatus(OrderStatus.BEFORECANCEL.getCode());
        }
        // 未接单取消
        if(Integer.parseInt(databaseOrder.getOrderStatus()) < 4){
            // 未接单状态取消，状态变为已取消（接单前）
            orderManage.setOrderStatus(OrderStatus.BEFORECANCEL.getCode());
        }
        // 接单后取消
        if(OrderStatus.ONGOING.getCode().equals(databaseOrder.getOrderStatus())){
            // 进行中状态取消，状态变为已取消（接单后）
            orderManage.setOrderStatus(OrderStatus.AFTERCANCEL.getCode());
        }

        // 创建人是登陆人
        if(StringUtils.isNotEmpty(databaseOrder.getCreateBy()) && StringUtils.isNotEmpty(SecurityUtils.getUsername())
                && databaseOrder.getCreateBy().equals(SecurityUtils.getUsername())){
            orderManage.setCancelReason(CancelReason.MYSELF.getCode());
        }else{
            orderManage.setCancelReason(CancelReason.SYSTEM.getCode());
        }

        int i = orderManageMapper.updateCancelOrder(orderManage);
        // 接单后取消通知接单人
        if(OrderStatus.AFTERCANCEL.getCode().equals(orderManage.getOrderStatus())) {
            asyncService.executeAsyncSendCancelMsg(orderManage);
        }
        return i;
    }

    /**
     * 撤销工单
     * @param orderManage
     * @return
     */
    @Override
    public int revokeOrder(OrderManage orderManage) {
        OrderManage databaseOrder = orderManageMapper.selectOrderManageById(orderManage.getId());
        // 未查询到工单
        if(null == databaseOrder){
            throw new ServiceException("未查询到当前工单,请联系管理员处理");
        }
        // 置空接单人、接单时间，修改状态
        int i = orderManageMapper.updateOrderManageForRevoke(databaseOrder.getId());
        if (i > 0) {
            // 通知运维
            asyncService.executeAsyncSendGrabMsg(databaseOrder);
            // 通知报单人
            asyncService.executeAsyncSendRevokeMsg(databaseOrder);
        }
        return i;
    }

    /**
     * 功能描述:    确认完成工单
     *
     * @Author wanghc
     * @Date 2022/08/22 16:48
     * @param orderManage 工单
     * @return int
     */
    @Override
    public int finishOrder(OrderManage orderManage) {
        OrderManage databaseOrder = orderManageMapper.selectOrderManageById(orderManage.getId());
        // 未查询到工单
        if(null == databaseOrder){
            throw new ServiceException("未查询到当前工单,请联系管理员处理");
        }
        // 工单状态为空
        if(StringUtils.isEmpty(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单状态缺失，请联系管理员处理");
        }
        // 工单已取消
        if(OrderStatus.BEFORECANCEL.getCode().equals(databaseOrder.getOrderStatus()) ||
                OrderStatus.AFTERCANCEL.getCode().equals(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单已取消，不能执行完工操作");
        }
        // 接单后取消
        if(OrderStatus.ONGOING.getCode().equals(databaseOrder.getOrderStatus())){
            // 进行中状态确认完成，状态变为已完成
            orderManage.setOrderStatus(OrderStatus.FINISHED.getCode());
        }
        int i = orderManageMapper.updateFinishOrder(orderManage);
        // 完成工单通知报单人
        if(OrderStatus.FINISHED.getCode().equals(orderManage.getOrderStatus())){
            asyncService.executeAsyncSendFinishMsg(orderManage);
        }
        return i;
    }

    /**
     * 功能描述:    评价工单
     *
     * @Author wanghc
     * @Date 2022/08/23 03:30
     * @param orderManage
     * @return int
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int evaluateOrder(OrderManage orderManage) {
        OrderManage databaseOrder = orderManageMapper.selectOrderManageById(orderManage.getId());
        // 未查询到工单
        if(null == databaseOrder){
            throw new ServiceException("未查询到当前工单,请联系管理员处理");
        }
        // 工单状态为空
        if(StringUtils.isEmpty(databaseOrder.getOrderStatus())){
            throw new ServiceException("工单状态缺失，请联系管理员处理");
        }
        // 未完成评价
        if(Integer.parseInt(databaseOrder.getOrderStatus()) < 7){
            throw new ServiceException("工单未完成，不能评价");
        }
        // 未完成评价
        if(OrderStatus.EVALUATED.getCode().equals(databaseOrder.getOrderStatus())){
            throw new ServiceException("当前工单已评价");
        }
        // 接单后取消
        if(OrderStatus.FINISHED.getCode().equals(databaseOrder.getOrderStatus())){
            // 已完成状态做出评价，状态变为已评价
            orderManage.setOrderStatus(OrderStatus.EVALUATED.getCode());
        }
        return orderManageMapper.updateEvaluateOrder(orderManage);
    }

    /**
     * 功能描述:   小程序查询各种类型工单数量
     *
     * @Author wanghc
     * @Date 2022/08/25 16:52
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Integer>
     */
    @Override
    public Map<String, Integer> getOrderNum() {
        Map<String, Integer> numMap = new HashMap<>();
        // 初始化工单各种状态数量均为0
        OrderNum orderNum = OrderNum.builder()
                .totalCount(0)
                .otherCount(0)
                .cancelCount(0)
                .grabCount(0)
                .ongoingCount(0)
                .finishedCount(0).build();
        if(null != SecurityUtils.getLoginUser() && null != SecurityUtils.getLoginUser().getUser()){
            String userName = SecurityUtils.getLoginUser().getUser().getUserName();
            if(StrUtil.isNotEmpty(userName)){
                List<String> roleKeyList = userService.selectUserRoleKeyList(userName);
                // 用户角色
                if(!CollectionUtils.isEmpty(roleKeyList) && roleKeyList.contains(RoleKey.USER.getCode())){
                    OrderNum dbOrderNum = orderManageMapper.countUserOrder(userName);
                    if(null != dbOrderNum){
                        orderNum = dbOrderNum;
                    }
                }else if(!CollectionUtils.isEmpty(roleKeyList) && roleKeyList.contains(RoleKey.OPT.getCode())){
                    // 运维角色
                    OrderNum dbOrderNum = orderManageMapper.countOptOrder(userName);
                    if(null != dbOrderNum){
                        orderNum = dbOrderNum;
                    }
                    // 待派单数量需要特殊处理，查询所有待派单的工单数量
                    OrderNum grabOrderNum = orderManageMapper.countAdminOrder();
                    if(null != grabOrderNum && null != grabOrderNum.getGrabCount()){
                        orderNum.setGrabCount(grabOrderNum.getGrabCount());
                    }
                    orderNum.setCancelCount(null == orderNum.getCancelCount() ? 0 : orderNum.getCancelCount());
                    orderNum.setGrabCount(null == orderNum.getGrabCount() ? 0 : orderNum.getGrabCount());
                    orderNum.setOtherCount(null == orderNum.getOtherCount() ? 0 : orderNum.getOtherCount());
                    orderNum.setOngoingCount(null == orderNum.getOngoingCount() ? 0 : orderNum.getOngoingCount());
                    orderNum.setFinishedCount(null == orderNum.getFinishedCount() ? 0 : orderNum.getFinishedCount());
                    orderNum.setTotalCount(orderNum.getCancelCount() + orderNum.getGrabCount()
                            + orderNum.getOtherCount() + orderNum.getOngoingCount() + orderNum.getFinishedCount());
                }else if(!CollectionUtils.isEmpty(roleKeyList) && (roleKeyList.contains(RoleKey.MANAGE.getCode()) ||
                        roleKeyList.contains(RoleKey.ADMIN.getCode()))){
                    // 管理员和超级管理员权限
                    OrderNum dbOrderNum = orderManageMapper.countAdminOrder();
                    if(null != dbOrderNum){
                        orderNum = dbOrderNum;
                    }
                }
            }
        }
        numMap.put("totalCount", null == orderNum.getTotalCount() ? 0 : orderNum.getTotalCount());
        numMap.put("grabCount", null == orderNum.getGrabCount() ? 0 : orderNum.getGrabCount());
        numMap.put("ongoingCount", null == orderNum.getOngoingCount() ? 0 : orderNum.getOngoingCount());
        numMap.put("finishedCount", null == orderNum.getFinishedCount() ? 0 : orderNum.getFinishedCount());
        return numMap;
    }

}
